/* eslint-disable no-param-reassign */
import { config } from '../../config/index';
import { request } from '../../utils/request';

/** 获取查询点评列表 */
function mockFetchReviewsList(classId=0) {
  const { delay } = require('../_utils/delay');
  const { getReviewsSearchResult } = require('../../model/search');
  
  const data = getReviewsSearchResult(classId);

  if (data.spuList.length) {
    data.spuList.forEach((item) => {
      item.spuId = item.reviewsId;
      item.thumb = item.primaryImage;
      item.title = item.title;
      // item.price = item.minSalePrice;
      // item.originPrice = item.maxLinePrice;
      item.desc = '';
      // if (item.spuTagList) {
      //   item.tags = item.spuTagList.map((tag) => tag.title);
      // } else {
      //   item.tags = [];
      // }
    });
  }
  return delay().then(() => {
    return data;
  });
}

/** 获取查询点评列表 */
export function fetchReviewsList(params) {
  if (config.useMock) {
    return mockFetchReviewsList(params);
  }
  return request('reviews/list', params, 'POST').then((res) => {
    return res;
  });
}